﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utilities;

namespace TokenApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnAuthenticate_Click(object sender, EventArgs e)
        {
            if (new UsersServ.WCFUsersClient().IsAuthenticationValid(txtUsername.Text, txtPassword.Text))
            {
                txtUsername.Enabled = false;
                txtPassword.Enabled = false;
                btnAuthenticate.Enabled = false;

                gbxB.Visible = true;
            }
            else
            {
                MessageBox.Show("Account details are invalid! Please try again.");
                gbxB.Visible = false;
            }
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            Encryption ea = new Encryption();
            string tp = "";
            
            try
            {
                tp = ea.EncryptTripleDES(txtPassword.Text, txtPIN.Text);
                int.Parse(txtPIN.Text);
            }
            catch
            {
                MessageBox.Show("Could not generate password. Make sure PIN number isn't left empty!");
            }

            if (tp != "")
            {
                MessageBox.Show("This is your token password: " + tp + " keep this token password safe, use it to report faults.");
                txtPIN.Enabled = false;
                btnGenerate.Enabled = false;
            }
           
        }

       
    }
}
